﻿using PescarShop_1.Models;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;

namespace PescarShop_1.Controllers
{
    public class WebApiController : ApiController
    {
        private ShopContext db = new ShopContext();

        [HttpGet]
        public IEnumerable Busqueda(String term = "")
        {
            if (term == null || term == "")
            {
                var resultado = db.productos;
                return resultado.ToList();
            }
            else
            {
                var resultado = from prod in db.productos
                                where prod.Nombre.Contains(term)
                                || (prod.Descripcion.Contains(term))
                                || (prod.Marca.Nombre.Contains(term))
                                select prod;
                return resultado.ToList();
            }
        }
    }
}
